const initState = () => {
    return {
        isLogin: false,
        token: '',
        company: '',
        address: '',
        sellTotal: 0, // 已售
        rentingTotal: 0, // 在租
        depositTotal: 0, // 押金
        merchantId: '', // 商户id
        balance: 0, // 余额
        rentable: 0, // 是否开通租赁
        marketable: 0, // 是否开通售卖
        mainUser: false, // 是否是主账号本人
    }
}

export default {
    namespaced: true,
    state: initState(),
    mutations: {
        setParams (state, params) {
            for (const [key, value] of Object.entries(params)) {
                if (state.hasOwnProperty(key)) {
                    state[key] = value
                }
            }
            uni.setStorageSync('zzk:user', state)
        }
    },
    actions: {
        getParams ({ commit }) {
            const info = uni.getStorageSync('zzk:user')
            if (info) {
                commit('setParams', info)
            }
        },
        loginOut ({ commit }) {
            commit('setParams', initState())
        }
    },
};